package com.welink.web.resource;

import com.welink.web.common.action.BaseAction;
import org.slf4j.LoggerFactory;

/**
 * Created by daniel on 14-12-23.
 * 生成二维码
 */
public class GenQr extends BaseAction {

    private static org.slf4j.Logger log = LoggerFactory.getLogger(GenQr.class);

    private String url = "https://open.weixin.qq.com/connect/oauth2/authorize";

    private String charset = "utf-8";

    private String AppId = "wx07d7e44f348d48f5";

    private String AppSecret = "a8a699b61085c4b0c250f453e3eb52f8";

    @Override
    public String execute() throws Exception {
//        SSLHttpClientUtil httpClientUtil = new SSLHttpClientUtil();
//        //获取二维码
//        //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
//        String wholeAccTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppId + "&secret=" + AppSecret;
//        String wholeAccResult = httpClientUtil.doGet(wholeAccTokenUrl);
//        WholyAccTokenModel wAccToken = null;
//        if (StringUtils.isNotBlank(wholeAccResult)) {
//            wAccToken = JSON.parseObject(wholeAccResult, WholyAccTokenModel.class);
//        } else {
//            //TODO:获取token失败
//        }
//        String actionInfo = "{\"action_name\": \"QR_LIMIT_SCENE\",\"action_info\": {\"scene\": {\"scene_id\": 1000}}}";
//        String QRCodeUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wAccToken.getAccess_token();
//        String QRCodeStr = httpClientUtil.doPostJson(QRCodeUrl, actionInfo, "utf-8");
//
//        WeChatTicketModel wTicket = null;
//        if (StringUtils.isNotBlank(QRCodeStr)){
//            wTicket = JSON.parseObject(QRCodeStr, WeChatTicketModel.class);
//        }else {
//            //TODO:error
//        }
//        //通过ticket换取二维码
//        //https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
//        String qRcodeFetchUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ URLEncoder.encode(wTicket.getTicket());
//        InputStream qrcode = httpClientUtil.doGetAsStream(qRcodeFetchUrl);
//
//        ServletActionContext.getContext().put("imageStream", qrcode);
        return "processImage";
    }
}
